<include file="../header" />

<script type="text/javascript" src="/Template/js/vue.min.js"></script>

<body class="J_scroll_fixed" id="container">
<script type="text/javascript">
    $(function() {
        $(".search").click(function() {
            $("select[name=codeId]").show();
            $("select[name=codeId]").empty();
            $("select[name=codeId]").append("<option value='0'></option>");
            var codeName = $("input[name=codeName]").val();
            var levelCodeArr=<?php echo json_encode($levelCode);?>;

            for(var i=0;i<levelCodeArr.length;i++){
                if(levelCodeArr[i]["full_name"].indexOf(codeName) != -1 && levelCodeArr[i]["level"] == 1 && levelCodeArr[i]["material_id"] == null){
                    $("select[name=codeId]").append("<option value='"+levelCodeArr[i]["code_id"]+"'>【"+levelCodeArr[i]["parent_name"]+"】"+levelCodeArr[i]["code_name"]+"</option>");

                }
            }
        });


        $("button.btn_submit").click(function() {
           if($("select[name=codeId]").val() == 0){
                alert("请选择【编码】");
                $("select[name=codeName]").focus();
                return false;
            }
            if($("input[name=name]").val() == ""){
                alert("请填写【名称】");
                $("input[name=name]").focus();
                return false;
            }
            if($("input[name=spec]").val() == ""){
                alert("请填写【规格型号】");
                $("input[name=spec]").focus();
                return false;
            }
            if($("select[name=unit]").val() == 0){
                alert("请选择【单位】");
                $("select[name=codeName]").focus();
                return false;
            }

            $("button.btn_submit").hide();

        });

    })

</script>

<div class="wrap jj">
    <div class="common-form">
        <form method="post" class="form-horizontal J_ajaxForm" action="{:U('Material/addPost')}">
            <fieldset>
                <div class="control-group">
                    <label class="control-label">编码：</label>
                    <div class="controls">
                        <select name="codeId" style="display: none">
                            <option value='0'></option>
                        </select>
                        <input type="text" class="input" name="codeName" value="">
                        <a class="btn btn-success search">搜索</a>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">名称：</label>
                    <div class="controls">
                        <input type="text" class="input" name="name" value="">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">规格型号：</label>
                    <div class="controls">
                        <input type="text" class="input" name="spec" value="">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">辅助属性：</label>
                    <div class="controls">
                        <input type="text" class="input" name="prop" value="">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">单位：</label>
                    <div class="controls">
                        <select name="unit">
                            <option value='0'></option>
                            <option value='张'>张</option>
                            <option value='个'>个</option>
                            <option value='只'>只</option>
                            <option value='套'>套</option>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">条形码：</label>
                    <div class="controls">
                        <input type="text" class="input" name="barcode" value="">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">备注：</label>
                    <div class="controls">
                        <textarea style="height:6rem;" name="remark"></textarea>
                    </div>
                </div>
            </fieldset>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary btn_submit">添加</button>
                <a class="btn" href="__URL__">返回</a>
            </div>
        </form>
    </div>
</div>
<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>